package com.ys.erp.entity.data.bean;

import com.baomidou.mybatisplus.annotation.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;

import java.time.LocalDateTime;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;

/**
 * @author lwj
 * @date 2025/6/20
 */
    
/**
 * 支付宝转账分账订单表
 */
@Data
@TableName(value = "t_zfb_separate_account_order")
public class ZfbSeparateAccountOrder {
    /**
     * 主键
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    /**
     * 订单号
     */
    @TableField(value = "order_no")
    private String orderNo;

    /**
     * 订单号
     */
    @TableField(value = "source_order_no")
    private String sourceOrderNo;

    @TableField(value = "source_order_type")
    private String sourceOrderType;

    /**
     * 微分呗期数
     */
    @TableField(value = "period")
    private Integer period;

    /**
     * 本期金额
     */
    @TableField(value = "amount")
    private Long amount;

    /**
     * 微分呗分账金额
     */
    @TableField(value = "separate_amount")
    private Long separateAmount;

    /**
     * 店铺编号
     */
    @TableField(value = "shop_code")
    private String shopCode;

    /**
     * 店铺名称
     */
    @TableField(value = "shop_name")
    private String shopName;

    /**
     * 分账比列
     */
    @TableField(value = "separate_ratio")
    private String separateRatio;

    /**
     * 出账支付宝账户
     */
    @TableField(value = "origin_zfb_account")
    private String originZfbAccount;

    /**
     * 支付宝账户
     */
    @TableField(value = "zfb_account")
    private String zfbAccount;

    /**
     * 支付宝身份证号
     */
    @TableField(value = "zfb_id_card")
    private String zfbIdCard;

    /**
     * 支付宝名字
     */
    @TableField(value = "zfb_name")
    private String zfbName;

    /**
     * 支付宝订单id
     */
    @TableField(value = "zfb_order_id")
    private String zfbOrderId;

    /**
     * 支付宝支付id
     */
    @TableField(value = "zfb_pay_fund_order_id")
    private String zfbPayFundOrderId;

    /**
     * 支付宝业务场景
     */
    @TableField(value = "zfb_biz_scene")
    private String zfbBizScene;

    /**
     * 支付宝产品码
     */
    @TableField(value = "zfb_product_code")
    private String zfbProductCode;

    /**
     * 发起时间
     */
    @TableField(value = "init_time")
    private LocalDateTime initTime;

    /**
     * 交易时间
     */
    @TableField(value = "trans_time")
    private LocalDateTime transTime;

    /**
     * 版本号
     */
    @TableField(value = "version")
    @Version
    private Integer version;

    /**
     * 创建时间
     */
    @TableField(value = "create_time")
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @TableField(value = "update_time", update = "now()")
    private LocalDateTime updateTime;


    @AllArgsConstructor
    @Getter
    public enum Enums {

        WFB,
        HUA_BEI,
        JDBT,
        ;

    }

    public static final Map<String, String> ENUM_MAP = new HashMap<>();

    static {
        ENUM_MAP.put(ZfbSeparateAccountOrder.Enums.WFB.name(), "微分呗");
        ENUM_MAP.put(ZfbSeparateAccountOrder.Enums.HUA_BEI.name(), "花呗");
        ENUM_MAP.put(ZfbSeparateAccountOrder.Enums.JDBT.name(), "京东白条");
    }


    public static String getRandOrderNo() {
        Calendar calendar = Calendar.getInstance();
        int month = calendar.get(Calendar.MONTH) + 1;
        int day = calendar.get(Calendar.DATE);
        return  "ZFB"
                + calendar.get(Calendar.YEAR)
                + (month >= 10 ? String.valueOf(month) : "0" + month)
                + (day >= 10 ? String.valueOf(day) : "0" + day)
                + calendar.get(Calendar.HOUR_OF_DAY)
                + calendar.get(Calendar.MINUTE)
                + calendar.get(Calendar.SECOND)
                + ((int)((Math.random()*9+1)*10000000));
    }

    @Data
    public static class SeparateAccountDTO {

        //微分呗订单号
        private String orderNo;

        //类型
        private String type;

        //期数
        private Integer period;

        //金额
        private Long amount;

//        //是否转入Hz123
//        private Integer isToHz123 = 0;
//
//        //转入Hz123金额
//        private Long toHz123Amount;

    }

    @EqualsAndHashCode(callSuper = true)
    @Data
    public static class SeparateAccountFailDTO extends SeparateAccountDTO{

        //失败描述
        private String failDes;

        //店铺编号
        private String shopName;

        //分账比例
        private String ratio;

        //分账金额
        private Long separateAmount;

    }

}